<template>
  <div class="navbar fn df aic jcsb">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item
        v-for="item in breadList"
        :key="item.path"
        :to="item.path"
      >
        {{ item.title }}
      </el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 右边 -->
    <div class="r df aic">
      <!-- 下拉框 -->
      <el-dropdown>
        <span class="el-dropdown-link">
          下拉菜单
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>黄金糕</el-dropdown-item>
          <el-dropdown-item>狮子头</el-dropdown-item>
          <el-dropdown-item>螺蛳粉</el-dropdown-item>
          <el-dropdown-item disabled>双皮奶</el-dropdown-item>
          <el-dropdown-item divided>蚵仔煎</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <!-- 头像 -->
      <el-avatar :size="40" :src="avatar"></el-avatar>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      avatar: '',
      //面包屑占位
      breadList: [],
    }
  },
  //计算面包屑---方法一
  methods: {
    //先封装一个函数 处理面包屑导航的函数
    calcBreadList() {
      let temp = [{path: '/', title: '首页'}]
      this.$route.matched.forEach(item => {
        if (item.path != '') {
          //判断  不为空的时候才往数组中追加数据
          temp.push({path: item.path, title: item.meta.title})
        }
      })
      this.breadList = temp
    },
  },

  //在监听到hash变化的时候，还要计算一下面包屑导航--侦听器
  watch: {
    $route() {
      this.calcBreadList()
    },
  },

  created() {
    // console.log('this.$route :>> ', this.$route)
    console.log('this.$route.matched :>> ', this.$route.matched)
    // 初始化在created生命周期调用一下计算面包屑的函数
    this.calcBreadList()
  },
}
</script>

<style lang="scss" scoped>
.navbar {
  height: 64px;
  padding: 0 15px;
}
.el-avatar {
  margin-left: 15px;
}
</style>
